//
//  UIBarButtonItem+Extension.swift
//  swiftweibo
//
//  Created by ffxk007 on 2017/6/16.
//  Copyright © 2017年 ffxk007. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    
    convenience init(title:String,fonSize:CGFloat = 16,target:AnyObject?,action:Selector,isBackButton:Bool = false) {
        let btn:UIButton = UIButton()
//        btn.frame = CGRect(x: 0, y: 0, width: 50, height: 50)
        
        btn.titleLabel?.font = UIFont.systemFont(ofSize: fonSize)
        btn.setTitle(title, for: UIControlState.normal)
        btn.setTitleColor(UIColor.darkGray, for: UIControlState.normal)
        btn.setTitleColor(UIColor.orange, for: UIControlState.highlighted)
        btn.addTarget(target, action: action, for: .touchUpInside)
//        btn.addTarget(<#T##target: Any?##Any?#>, action: <#T##Selector#>, for: <#T##UIControlEvents#>)
        if isBackButton {
            let imageName = "WechatIMG"
            btn.setImage(UIImage(named:imageName), for: UIControlState(rawValue: 0))
            btn.setImage(UIImage(named:imageName + "_highlighted"), for: .highlighted)
            btn.sizeToFit()
        }
        btn.sizeToFit()
        self.init(customView: btn)
    }
}
